package com.edu.control;


import com.edu.javaBean.Register;
import com.edu.javaBean.User;
import com.edu.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    //获取最大病历号
    @RequestMapping(value = "/getMaxCaseNum",method = RequestMethod.GET)
    public String getMaxCaseNum(){
        return registerService.getMaxCaseNum();
    }
    //查询已用挂号额度
    @RequestMapping(value = "/getExsitsQuota",method = RequestMethod.GET)
    public int getExsitsQuota(String visitedate,String noon,int userid){
        return registerService.getExsitsQuota(visitedate,noon,userid);
    }
    //保存挂号信息
    @RequestMapping(value = "/saveRegister",method =RequestMethod.POST )
    public Map<String,String> saveRegister(@RequestBody Map<String,Object> map, HttpSession session){
        int i=registerService.saveRegister(map,session);
        Map<String,String> res=new HashMap<>();

        if(i>0){
            res.put("type","success");
            res.put("msg","挂号成功");
        }else {
            res.put("type","warning");
            res.put("msg","挂号失败");
        }
        return res;
    }
    //查询待诊患者列表
    @RequestMapping("/getWaitingRegs")
    public List<Register> getWaitingRegs(HttpSession session){
        //获取当前医生登录的id
       User user=(User) session.getAttribute("userInfo");
        return registerService.getWaitingRegs(user.getId());
    }
}
